
function selectMerchandise(merchandise_id){
	var url = '/storage/manager/pages/merchandise.do?method=selectMerchandise&d=' + new Date();
	url = url + '&merchandise_id='+merchandise_id;
	
	$.getJSON(url, {}, function(data){
		var merchandise_id = document.getElementById('merchandise_id');
		var merchandise_cid  =  document.getElementById('merchandise_cid'); 
		var merchandise_name =  document.getElementById('merchandise_name');
		var parent_type      =  document.getElementById('parent_type');
		var merchandise_type =  document.getElementById('merchandise_type');
		var merchandise_norm =  document.getElementById('merchandise_norm');
		var merchandise_unit =  document.getElementById('merchandise_unit');
		var merchandise_memo =  document.getElementById('merchandise_memo');
		var merchandise_low_alert = document.getElementById('merchandise_low_alert');
		var merchandise_height_alert = document.getElementById('merchandise_height_alert');
		
		parent_type.value = data[0][9];
		selectMerchandiseType();
		setTimeout(function (){
			merchandise_id.value = data[0][0];
			merchandise_cid.value = data[0][1];
			merchandise_name.value = data[0][2];
			merchandise_norm.value = data[0][4];
			merchandise_unit.value = data[0][11];
			merchandise_low_alert.value = data[0][7];
			merchandise_height_alert.value = data[0][12];
			merchandise_memo.value = data[0][8];
			merchandise_type.value = data[0][10];
		},500);
	});
};
function saveOrUpdate(){
	var merchandise_id = document.getElementById('merchandise_id').value;
	var merchandise_cid = $('#merchandise_cid').val();
	var merchandise_name = $('#merchandise_name').val();
	var parent_type = $('#parent_type').val();
	var merchandise_type = $('#merchandise_type').val();
	var merchandise_norm = $('#merchandise_norm').val();
	var merchandise_unit = $('#merchandise_unit').val();
	
	var isFull = ''!=merchandise_cid&&''!=merchandise_name&&''!=parent_type&&''!=merchandise_type&&''!=merchandise_norm&&''!=merchandise_unit;
	
	if(isFull){
		merchandise_id==''?save():update();
	}else{
		alert('必要信息不完整');
	}
};
function save(){

	var merchandise_cid = escape(escape($('#merchandise_cid').val()));
	var merchandise_name = escape(escape($('#merchandise_name').val()));
	var parent_type = escape(escape($('#parent_type').val()));
	var merchandise_type = escape(escape($('#merchandise_type').val()));
	var merchandise_norm = escape(escape($('#merchandise_norm').val()));
	var merchandise_unit = escape(escape($('#merchandise_unit').val()));
	var merchandise_memo = escape(escape($('#merchandise_memo').val()));
	var merchandise_low_alert = escape(escape($('#merchandise_low_alert').val()));
	var merchandise_height_alert = escape(escape($('#merchandise_height_alert').val()));
	
	var url = '/storage/manager/pages/merchandise.do?method=create&d=' + new Date();
	url = url + '&merchandise_cid=' + merchandise_cid;
	url = url + '&merchandise_name=' + merchandise_name;
	url = url + '&parent_type=' + parent_type;
	url = url + '&merchandise_type=' + merchandise_type;
	url = url + '&merchandise_norm=' + merchandise_norm;
	url = url + '&merchandise_unit=' + merchandise_unit;
	url = url + '&merchandise_memo=' + merchandise_memo;
	url = url + '&merchandise_low_alert=' + merchandise_low_alert;
	url = url + '&merchandise_height_alert=' + merchandise_height_alert;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("保存成功");
			window.close();
		}else{
			alert("保存失败");
		}
	});
};
function update(){
	
	var merchandise_id = escape(escape($('#merchandise_id').val()));
	var merchandise_cid = escape(escape($('#merchandise_cid').val()));
	var merchandise_name = escape(escape($('#merchandise_name').val()));
	var parent_type = escape(escape($('#parent_type').val()));
	var merchandise_type = escape(escape($('#merchandise_type').val()));
	var merchandise_norm = escape(escape($('#merchandise_norm').val()));
	var merchandise_unit = escape(escape($('#merchandise_unit').val()));
	var merchandise_memo = escape(escape($('#merchandise_memo').val()));
	var merchandise_low_alert = escape(escape($('#merchandise_low_alert').val()));
	var merchandise_height_alert = escape(escape($('#merchandise_height_alert').val()));
	
	var url = '/storage/manager/pages/merchandise.do?method=update&d=' + new Date();
	url = url + '&merchandise_id=' + merchandise_id;
	url = url + '&merchandise_cid=' + merchandise_cid;
	url = url + '&merchandise_name=' + merchandise_name;
	url = url + '&parent_type=' + parent_type;
	url = url + '&merchandise_type=' + merchandise_type;
	url = url + '&merchandise_norm=' + merchandise_norm;
	url = url + '&merchandise_unit=' + merchandise_unit;
	url = url + '&merchandise_memo=' + merchandise_memo;
	url = url + '&merchandise_low_alert=' + merchandise_low_alert;
	url = url + '&merchandise_height_alert=' + merchandise_height_alert;
	
	$.getJSON(url, {}, function(data){
		if(data=="true"){
			alert("保存成功");
			window.close();
		}else{
			alert("保存失败");
		}
	});
};